#include <iostream>

#include "commons/x264_encoder.h"
#include "commons/libar8020.h"

int main() {
  if (Usb_Init_So()<0) {
    printf({"error init use\n"});
    return -1;
  }
  std::cout << "Hello World!" << std::endl;
  cv::Mat frame, frame_dst;
  cv::VideoCapture cap("/home/robot/zhangyiyang/catkin_ws/src/model_prediction/tests/data/whj.mp4");
  assert(cap.isOpened());
  x264Encoder m_x264Encoder(640, 480, 3, 25);
  int jpeg_quality = 75;
  std::vector<int> params;
  params.push_back(cv::IMWRITE_JPEG_QUALITY);
  params.push_back(jpeg_quality);

  while (1) {
    cap >> frame;
    cv::resize(frame, frame, cv::Size(640, 480));
    if (frame.empty()) break;
    cv::imshow("demo", frame);
    cv::waitKey(1);
    int size = m_x264Encoder.EncodeOneFrame(frame);
    uchar* data = nullptr;
    data = m_x264Encoder.GetEncodedFrame();
    std::cout << "type " << frame.type() << " size " << size << std::endl;
    Video_Port_Send_So((char*)data, size);
  }

  cap.release();
  return 0;
}
